package com.example.module_web.view.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.module_web.R;
import com.example.module_web.adapter.OrderAdapter;
import com.example.module_web.base.BaseFragmentB;
import com.example.module_web.beans.Order;
import com.example.module_web.viewmodule.NetData_Web;

import java.util.List;

/**
 * Created by Administrator on 2018/2/19.
 */

public class Fragment_00 extends BaseFragmentB {
    private static final String TAG = "bug";
    private List<Order> mOrders;
    private RecyclerView mRecyOrder;


    @Override
    protected int setLayoutId() {
        return R.layout.web_fragment_00;
    }
    @Override
    protected void initView(View view) {
        mRecyOrder = view.findViewById(R.id.web_frag00_recy_order);
    }

    @Override
    protected void initEvent(Context context, Bundle savedInstanceState) {
        setupRecyclerData(context);
    }


    public void setupRecyclerData(Context context) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyOrder.setLayoutManager(layoutManager);
        mRecyOrder.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));

        loadNetData(context);
    }

    private void loadNetData(final Context context) {

        NetData_Web.getInstance().getOrders(context, "RecentOrder", new NetData_Web.Singer<List<Order>>() {
            @Override
            public void success(List<Order> orders) {
                mOrders = orders;
                OrderAdapter orderAdapter = new OrderAdapter(context, orders);
                mRecyOrder.setAdapter(orderAdapter);
            }

            @Override
            public void failed(String s) {

            }
        });
    }
}
